<template>
	<view class="app_Cont">
		<view class="showCont">
		
			<view class="formCont">
				<view class="formTitle">合作申请</view>
				<view class="formItem">
					<view class="inputName">
					    <view class="mustIcon">*</view>
					    <view class="inputNameText">您的称呼</view>
				    </view>
					<view class="inputValue">
						<input maxlength="20" v-model="formData.real_name" placeholder="请输入对您的称呼"  />
					</view>
				</view>
				<view class="formItem">
					<view class="inputName">
					    <view class="mustIcon">*</view>
					    <view class="inputNameText">您的性别</view>
				    </view>
					<view class="inputOut">
						<view class="inputMask" @click="showSex = true"></view>
						<input
						  v-model="formData.sex"
						  placeholder="请选择您的性别"
						/>
					</view>
					<view
						@click="showSex = true"
						class="iconfont icon-xiala"
					></view>
				</view>
				<view class="formItem">
					<view class="inputName">
					    <view class="mustIcon">*</view>
					    <view class="inputNameText">手机号</view>
				    </view>
					<view class="inputValue">
						<input maxlength="11" type="number" v-model="formData.mobile" placeholder="请输入手机号"  />
					</view>
					<view :class="!isGetting&&checkPhone()?'getCode':'getCode disCode'" @click="getCode">{{codeText}}</view>
				</view>
				<view class="formItem">
					<view class="inputName">
					    <view class="mustIcon">*</view>
					    <view class="inputNameText">验证码</view>
				    </view>
					<view class="inputValue">
						<input maxlength="4" type="number" v-model="formData.code" placeholder="请输入验证码"  />
					</view>
				</view>
			</view>
			<view class="saveBtn" @click="saveFn">提交合作申请</view>
			<u-notify ref="uNotify" ></u-notify>
			<u-toast ref="uToast"></u-toast>
			<subLoad v-if="showSub"></subLoad>
			<u-picker :show="showSex" @confirm="sexSureFn" @cancel="showSex = false" @close="showSex = false" :closeOnClickOverlay="true" :columns="sexArr"></u-picker>
		</view>
	</view>
</template>

<script>
	import ruleCheck from '@/utils/ruleCheck.js'
	import api from '@/http/api.js'
	import subLoad from '@/components/sub.vue'
	export default {
		components:{subLoad},
		data() {
			return {
				showSub:false,
				formData: {
					real_name:'',
					sex:'',
					mobile:'',
					code:'',
				},
				showSex:false,
				sexArr:[
					['先生','女士']
				],
				isGetting:false,
				codeText:'获取验证码',
			};
		},
		methods:{
			checkPhone(){
				return !ruleCheck.checkPhone(this.formData.mobile)
			},
			getCode() {
			  let result = !ruleCheck.checkPhone(this.formData.mobile);
			  if (!this.isGetting && result) {
				this.isGetting = true;
				let timer = null;
				let num = 60;
				this.getSendsms(this.formData.mobile);
				timer = setInterval(() => {
				  if (num > 0) {
					num--;
					this.codeText = num + "s后重试";
				  } else {
					this.codeText = "重新获取";
					this.isGetting = false;
					clearInterval(timer);
				  }
				}, 1000);
			  }
			},
			getSendsms(mobile) {
			  let data = {
				mobile: mobile,
			  };
			  this.showSub = true
			  api.getRequst(data,'/common/Sms').then((res)=>{
			  	if(res.code==1){
			  		this.$refs.uToast.show({
			  			message:'验证码已发送',
			  		})
			  	}
				this.showSub = false
			  })
			},
			sexSureFn(data){
				this.formData.sex  = data.value[0]
				this.showSex = false
			},
			saveFn(){
				let data = this.formData
				
				let tipData = {
					bgColor: '#e47470',
					message: '',
					safeAreaInsetTop:true,
				}
				if(!data.real_name){
					tipData.message = '请输入您的称呼'
					this.$refs.uNotify.show(tipData)
					return false
				}else if(!data.sex){
					tipData.message = '请选择您的性别'
					this.$refs.uNotify.show(tipData)
					return false
				}else if(ruleCheck.checkPhone(data.mobile)){
					tipData.message = ruleCheck.checkPhone(data.mobile)
					this.$refs.uNotify.show(tipData)
					return false
				}else if(data.code.length!=4){
					tipData.message = '验证码不正确'
					this.$refs.uNotify.show(tipData)
					return false
				}
				data.sex = data.sex=='先生'?1:2
				this.showSub = true
				api.getRequst(data,'/api/My/cooperateApply').then((res)=>{
					if(res.code==1){
						this.$refs.uToast.show({
							message:'申请已提交',
						})
						this.formData = {
							real_name:'',
							sex:'',
							mobile:'',
							code:'',
						}
					}
					this.showSub = false
				})
			}
		}
	}
</script>

<style lang="scss">
.showCont{
	min-height: 100vh;
	background-color: #f8f8f8;
	box-sizing: border-box;
	padding-bottom: 30rpx;
	.bannerCont{
		padding-top: 120rpx;
		background-image: linear-gradient(to bottom,#3f55cc,#f8f8f8);
		image{
			width: 100%;
		}
	}
	.formCont{
		background-color: #fff;
		border-radius: 30rpx;
		padding: 40rpx 30rpx 60rpx;
		width: 92%;
		margin: 30rpx auto 30rpx;
		box-sizing: border-box;
		.formTitle{
			font-size: 32rpx;
			margin-bottom: 30rpx;
			font-weight: bold;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.addBtn{
				font-size: 24rpx;
				font-weight: normal;
				color: #3f55cc;
			}
		}
		.formItem{
			margin-top: 30rpx;
			display: flex;
			align-items: center;
			background-color: #f8f8f8;
			padding: 25rpx 50rpx;
			box-sizing: border-box;
			border-radius: 50rpx;
			.inputName {
			  width: 140rpx;
			  position: relative;
			  font-size: 28rpx;
			  .mustIcon {
				font-size: 28rpx;
				top: 0;
				left: -16rpx;
				position: absolute;
				color: #ff5757;
			  }
			}
			.inputOut {
				flex: 1;
				width: 3rem;
				position: relative;
				.inputMask {
					width: 100%;
					height: 100%;
					position: absolute;
					left: 0;
					top: 0;
					z-index: 2;
				  }
				  input{
					width: 100%;
					border: none;
					background: none;
					outline: none;
					position: relative;
					z-index: 1;
				  }
			}
			.inputValue{
				flex: 1;
				width: 100rpx;
			}
			.getCode{
				font-size: 24rpx;
				color: #3f55cc;
			}
			.disCode{
				color:#999;
			}
			.icon-gouxuan1,.icon-xiala{
				color: #3f55cc;
			}
		}
		.bookItem{
			background-color: #f8f8f8;
			border-radius: 10rpx;
			padding: 30rpx;
			box-sizing: border-box;
			margin-top: 30rpx;
			.bookTop{
				display: flex;
				justify-content: space-between;
				align-items: center;
				.bookName{
					display: flex;
					align-items: center;
					font-weight: bold;
					font-size: 26rpx;
					.iconfont{
						margin-right: 15rpx;
					}
				}
			}
		}
		.formDesItem{
			display: flex;
			margin-bottom: 20rpx;
			.desName{
				color: #333;
				width: 120rpx;
				text-align: right;
				margin-right: 30rpx;
			}
		}
		.formDesMoney{
			display: flex;
			justify-content: flex-end;
			padding-top: 30rpx;
			border-top: 1px dashed #ddd;
			margin-top: 30rpx;
			align-items: center;
			.redText{
				color: #ff5757;
				font-size: 40rpx;
			}
		}
		.formMustRead{
			text-indent: 60rpx;
			line-height: 40rpx;
		}
	}
	.linkCont{
		width:100%;
		padding: 0 4%;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		color: #666;
		.checkBox{
			width: 24rpx;
			height: 24rpx;
			font-size: 24rpx;
			border-radius: 4rpx;
			border: 1px solid #ddd;
			background-color: #fff;
			color: #fff;
			text-align: center;
			line-height: 24rpx;
			margin-right: 15rpx;
		}
		.isCheck{
			background-color: #3f55cc;
			border: 1px solid #3f55cc;
		}
		.linkText{
			color: #3f55cc;
		}
	}
	.noBootm{
		padding-bottom: 30rpx;
	}
	.hasTop{
		margin-top: -170rpx;
	}
	.saveBtn{
		width: 92%;
		margin: 30rpx auto 0;
		border-radius: 50rpx;
		background-image: linear-gradient(to right bottom,#a3bffe,#3f55cc);
		color: #fff;
		font-size: 24rpx;
		padding: 30rpx 0;
		text-align: center;
		z-index: 2;
	}
}
</style>
